//
//  AuthViewModel.swift
//  Twitter
//
//  Created by shiyanjun on 2023/1/24.
//

import Foundation

class AuthViewModel: ObservableObject {
    @Published var userSession: User?
    
//    init() {
//        self.userSession = Auth.auth().currentUser
//
//        print("Debug: User session is \(String(describing: self.userSession))")
//    }
    
    func login(withEmail email: String, password: String) {
        print("Debug: Login with email \(email)")
//        Auth.auth().signIn(withEmail: email, password: password)
//        self.userSession = Auth.auth().currentUser
        let pwd = UserDefaults.standard.string(forKey: email)
        if pwd != nil && password == pwd {
            self.userSession = User(uid: "", email: email, password: password, fullname: "", username: "")
        }
    }
    
    func register(withEmail email: String, password: String, fullname: String, username: String) {
        
        
//        let user = Auth.auth().createUser(email: email, password: password, fullname: fullname, username: username)
        let pwd = UserDefaults.standard.set(password, forKey: email)
        
        print("Debug: Registed user successfully")
        print("Debug: user is \(String(describing: self.userSession))")
    }
}








































